
var __UIMain_instance = null;
function getUIMain() { return __UIMain_instance; }

var UIMain = function(){};

UIMain.prototype.onDidLoadFromCCB = function()
{   
    cc.log("UIMain.onDidLoadFromCCB");
    __UIMain_instance = this;
    

    // 初始化
    this.uiStory.setVisible(false);
    this.uiBattle.setVisible(false);
    this.uiBattleResult.setVisible(false);
    this.uiGarage.setVisible(true); // 显示车库

    getUIGarage().updateData();
};


// 关闭全部界面
UIMain.prototype.hideAll = function()
{
    if(this.uiStory.isVisible()) this.openUIStory(false);
}

UIMain.prototype.openUIBattleResult = function(isOpen)
{
    if(isOpen) this.hideAll();
    getUIBattleResult().onOpen(isOpen);
    this.uiBattleResult.setVisible(isOpen);
}

// 战役
UIMain.prototype.openUIStory = function(isOpen)
{
    if(isOpen) this.hideAll();
    getUIStory().onOpen(isOpen);
    this.uiStory.setVisible(isOpen);
}

// 全局播放战斗
UIMain.prototype.startBattle = function(missionId)
{
    this.onEnterBattleScene();

    BattleManager.initScene();
    BattleManager.enterBattlePve(missionId);
}

// 进入/退出战斗场景
UIMain.prototype.onEnterBattleScene = function()
{
    this.hideAll();

    this.uiBattle.setVisible(true);
    this.uiGarage.setVisible(false);

    // 车库
    getUIGarage().getGarage().setDeployEnabled(false);
}

UIMain.prototype.onExitBattleScene = function()
{
    this.uiBattle.setVisible(false);
    this.uiGarage.setVisible(true);

    // 车库
    getUIGarage().getGarage().setDeployEnabled(true);

    // 主界面按钮
    getUIGarage().clearSelectedBtn();
}

UIMain.prototype.message = function(msg)
{
    this.uiMsg.setString(msg);
}   

_debug = function(msg)
{
    var ui = getUIMain().uiDebug;
    var oldmsg = ui.getString();
    ui.setString(oldmsg + msg + '\n');
}